Distribution of Total Number of Orders vs. Order Hour of Day by Department

dept_hour_df = instacart |> 
  group_by(department, order_hour_of_day) |> 
  filter(!is.na(department) & !is.na(order_hour_of_day)) |> 
  summarize(total_orders = n())
## `summarise()` has grouped output by 'department'. You can override using the
## `.groups` argument.
dept_hour_df |> 
  plot_ly(x = ~order_hour_of_day, 
          y = ~total_orders, 
          color = ~department,
          type = "scatter",
          mode = "lines")
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Bar chart of the top 15 most ordered products

instacart |>
  count(product_name, sort = TRUE) |>
  slice_head(n = 15) |>
  plot_ly(
    x = ~reorder(product_name, n),
    y = ~n,
    type = "bar",
    orientation = "v"
  ) |>
  layout(
    title = "Top 15 Most Ordered Products",
    xaxis = list(title = "Product"),
    yaxis = list(title = "Orders")
  )

Box plot distributions of Add-to-Cart Orders by Department

top10_depts = instacart |>
  count(department, sort = TRUE) |>
  slice_head(n = 10) |>
  pull(department)

instacart |> 
  filter(department %in% top10_depts) |>
  plot_ly(
    x = ~department,
    y = ~add_to_cart_order,
    color = ~department,
    type = "box",
    boxpoints = "outliers",
    marker = list(opacity = 0.4),
    line = list(width = 1)
  ) |>
  layout(
    title = "Add-to-Cart Order by Department (Top 10)",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Add-to-Cart Position")
  )
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors